import { CopyControllerBase } from "./CopyControllerBase";
import { IView } from "../../../../mvc/interfaces/IView";
import { CrossTowerCopyInfoPanel } from "../crosstower/CrossTowerCopyInfoPanel";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { CrossTowerConfig } from "../../../resource/CrossTowerConfig";
import { DataEvent } from "../../../events/DataEvent";
import { ECopyType } from "../../../../../Message/Public/ECopyType";
import { SceneInfo } from "../../../scene/map/SceneInfo";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SMapPassPointList } from "../../../../../Message/Public/SMapPassPointList";
import { SCrossTowerInfo } from "../../../../../Message/Public/SCrossTowerInfo";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { GameController } from "../../../mvc/GameController";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
type int = number;
//class CrossTowerCopyController
    
    export  class CrossTowerCopyController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this._infoPanel) 
            {
                this._infoPanel = new CrossTowerCopyInfoPanel();
                this._infoPanel.autoUpdatePosition = true;
            }
            this._infoPanel.updatePosition();
            return this._infoPanel;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            Dispatcher.addEventListener(EventName.Scene_Update, this.onSceneUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.CrossTower_InfoUpdate, this.onCrossTowerInfoUpdate);
            return;
        }

        /* internal  */get infoPannel(): CrossTowerCopyInfoPanel
        {
            return this.view as CrossTowerCopyInfoPanel;
        }

        /* internal  */get towerConfig(): CrossTowerConfig
        {
            return CrossTowerConfig.instance;
        }

        /* internal  */onSceneUpdateHandler(arg1: DataEvent): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=null;
            if (cache.copy.isInCopyType(ECopyType._ECopyCrossTower)) 
            {
                loc1 = arg1.data as SceneInfo;
                loc2 = loc1.sMapDefine.mapId;
                loc3 = this._copy ? this._copy.code : 204;
                loc4 = this.towerConfig.getConfig(loc3, loc2);
                if (this.infoPannel) 
                {
                    this.infoPannel.updateInfos({"nextMap": true, "towerConfig": loc4});
                }
            }
            return;
        }

        /* internal  */onPassPointInfoChange(arg1: MessageBlock): void
        {
            var loc1=null;
            if (cache.copy.isInCopyType(ECopyType._ECopyCrossTower)) 
            {
                loc1 = arg1.messageBase as SMapPassPointList;
            }
            return;
        }

        /* internal  */onCrossTowerInfoUpdate(arg1: SCrossTowerInfo): void
        {
            var loc1=false;
            if (this.infoPannel) 
            {
                loc1 = false;
                if (this._curFloor != arg1.floor) 
                {
                    this._curFloor = arg1.floor;
                    loc1 = true;
                }
                this.infoPannel.updateInfos({"info": arg1, "isNext": loc1, "isPass": arg1.finished});
            }
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            this._copy = arg1;
            GameMapUtil.curMapState.isCrossTowerCopy = true;
            GameController.taskTrack.onShowOrHideTrack(false);
            NetDispatcher.dispatchCmd(ServerCommand.CrossGroup_PlayerInfoChange, cache.crossGroup.players);
            if (this.infoPannel) 
            {
                this.infoPannel.show();
            }
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            GameMapUtil.curMapState.isCrossTowerCopy = false;
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShowGameMainUI, true));
            GameController.taskTrack.onShowOrHideTrack(true);
            ThingUtil.passUtil.removeCachepass();
            if (this.infoPannel) 
            {
                this.infoPannel.dispose();
            }
            return;
        }

        /* internal */ /* const */MAX_FLOOR: int=4;

        /* internal */ /* var */_copy: TCopy;

        /* internal */ /* var */_curFloor: int;

        /* internal */ /* var */_infoPanel: CrossTowerCopyInfoPanel;
    }
